#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <string.h>
using namespace std;

int n;
int h[110];
int f[2][110];
int ans = 1000;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
        f[1][i]=f[0][i]=1;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = i - 1; j >= 1; j--)
        {
            if (h[j] < h[i])
                f[1][i] = max(f[1][j] + 1, f[1][i]);
        }
    } //正着求最长上升子序列
    for (int i = n; i >= 1; i--)
    {
        for (int j = i + 1; j <= n; j++)
        {
            if (h[j] < h[i])
            {
                f[0][i] = max(f[0][j] + 1, f[0][i]);
            }
        }
    } //反着求最长上升子序列
    for (int i = 1; i <= n; i++)
    {
        int temp = f[0][i] + f[1][i] - 1;
        ans = min(n - temp, ans);
    }
    cout << ans << endl;
    system("pause");
    return 0;
}